package com.guigu.hkw.realms;

import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.SimpleAuthenticationInfo;
import org.apache.shiro.authz.AuthorizationInfo;
import org.apache.shiro.crypto.hash.SimpleHash;
import org.apache.shiro.realm.AuthorizingRealm;
import org.apache.shiro.subject.PrincipalCollection;
import org.apache.shiro.util.ByteSource;

public class SHA1Realm extends AuthorizingRealm {
    protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principalCollection) {
        return null;
    }

    protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authenticationToken) throws AuthenticationException {
        //获取当前账号
        String principal = (String) authenticationToken.getPrincipal();
        System.out.println(principal);
        //获取盐值
        ByteSource bytes = ByteSource.Util.bytes(principal);
        //获取当前密码
        SimpleAuthenticationInfo simp=new SimpleAuthenticationInfo(principal,"77657a209a681f6a7e50e544069aee72f8fc3ada",bytes,getName());
        return simp;

    }
    public static void main(String[] args) {//盐值
        //salt在里面放用户名
        Object simpleHash = new SimpleHash("SHA1", "123","a",100000);
        System.out.println(simpleHash);

    }
}
